import {useEffect} from "react"

// import './Comp1.module.scss'

//模块化引入
import styles from './Comp1.module.scss'

const Comp=()=>{

  useEffect(()=>{
    console.log('123')
    //promise1
    const wait = (time:number) =>{
      return new Promise((resolve,reject)=>{
        setTimeout(()=>{
          resolve(time)
        },time)
      })
    }
    wait(1000).then(res=>console.log('等待一秒钟',res))

    //Promise2
    // const waitFindDom = (selector,config={timeout:0}) =>{
    //   let timeId
    //   const find = (resolve,reject) => {
    //     const el = document.querySelector(selector)
    //     if(el){
    //       resolve()
    //     } else {
    //       timeId = setTimeout(() => find(resolve,reject), 500)
    //     }
    //   }
    //   return new Promise((resolve,reject) => {
    //     find(resolve,reject)
    //     if(config.timeId>0) {
    //       setTimeout(()=>{
    //         clearTimeout(timeId)
    //         reject()
    //       },timeout)
    //     }
    //   })
    // }
    // waitFindDom(".xxx").then(res=>{console.log('找到啦')})

  },[])

  return(
    <div className={styles.box}>
      <p>这是comp1里面的内容</p>
      <div className='xxx'></div>
    </div>
  )
}

export default Comp